#include "Thread.hpp"
#include "../base/BaseLog.hpp"

#include <atomic>
#include <string>
#include <sys/syscall.h>
#include <unistd.h>

using namespace DBServer::coroutine;

static thread_local std::string t_name = "thread_";

static thread_local pid_t t_id = 0;

static std::atomic_uint64_t t_count = {0};

auto Thread::ThreadName() -> std::string& { return t_name; }

auto Thread::ThreadId() -> pid_t { return t_id; }

void Thread::set_name() { t_name += std::to_string(t_id) ; }

void Thread::set_id() {
    t_id = syscall(SYS_getpid);
    ++t_count;
}

void Thread::MainThread() {
    set_name();
    set_id();
    info("thread num : %ld\n", t_count.load());
}